# -*- coding;utf-8 -*-
"""
File name : auth.PY
Program IDE : PyCharm
Create file time: 2022/4/1 1:59
File Create By Author : 朱清闯
"""

from django.core.cache import cache
from rest_framework.authentication import BaseAuthentication
from rest_framework.exceptions import AuthenticationFailed


class Authentication(BaseAuthentication):
    def authenticate(self, request):
        token = request.META.get("HTTP_TOKEN")
        token_user = cache.get(token)
        if not token_user:
            raise AuthenticationFailed()
        else:
            return token_user, token

    def authenticate_header(self, request):
        # 不需要写
        pass
